from pms.common.views import PostFormula
from info.utils.notice import create_notice, notice_view
from project.models import Project
from department.models import Department


class API(PostFormula):

    def handle(self, req):
        return self.success_respond(
            notice_view(
                create_notice(
                    user=self.user,
                    title=req['title'],
                    content=req['content'],
                    department=Department.objects.get(id=req['did'])
                    if 'did' in req and req['did'] is not None else None,
                    project=Project.objects.get(id=req['pid'])
                    if 'pid' in req and req['pid'] is not None else None
                )
            )
        )
